--REQUIRES--

--DECLARACION DE VARIABLES GLOBALES--
posX=1.0
posY=1.0
posZ=1.0
speed =1.0
angSpeed = 0.90
charactersStateId = {}
charactersStates = {}

--DEFINICION DE FUNCIONES--

function NextEndPoint(liCharacterId)
	nextStateId = 1 + (charactersStateId[liCharacterId] % #charactersStates[liCharacterId])	
	nextPoint = charactersStates[liCharacterId][nextStateId]
	charactersStateId[liCharacterId] = nextStateId
	SetPatrolTarget(liCharacterId, nextPoint[1], nextPoint[2], nextPoint[3])
end

function DrawPath()
	for i = 1, #charactersStates do
		length = #charactersStates[i]
		for j = 1, length-1 do
			DrawLine(charactersStates[i][j][1],charactersStates[i][j][2],charactersStates[i][j][3],charactersStates[i][j+1][1],charactersStates[i][j+1][2],charactersStates[i][j+1][3])
		end
		DrawLine(charactersStates[i][length][1],charactersStates[i][length][2],charactersStates[i][length][3],charactersStates[i][1][1],charactersStates[i][1][2],charactersStates[i][1][3])
	end
end

--CODIGO LUA--

--Llamamos desde Lua a la funcion CreatePatrol definida en C++
--para crear un personaje y asociarle un comportamiento
ID=CreatePatrol(posX, posY, posZ, speed, angSpeed)
charactersStateId[ID] = 1
charactersStates[ID] = {{-3.0,1.0,-3.0},{-3.0,1.0,3.0},{3.0,1.0,3.0},{3.0,1.0,-3.0}}